import da from "element-ui/src/locale/lang/da";

function addZero(num){
    return num>10?num:0+""+num
}

export function formatDateTime(date = new Date()) {
    let seconds= addZero(date.getSeconds())
    let minute=addZero(date.getMinutes())
    let hour=addZero((date.getHours()))
    return date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " " + hour + ":" + minute + ":" + seconds
}

export function formatDate(date) {
    let origin
    if (date instanceof Date) {
        origin = date
    } else {
        origin = new Date(date)
    }


    let year = origin.getFullYear();    //  返回的是年份
    let month = origin.getMonth() + 1;  //  返回的月份上个月的月份，记得+1才是当月
    let dates = origin.getDate();
    if (month < 10) month = "0" + month;
    if (origin < 10) origin = "0" + origin;
    let time = year + "-" + month + "-" + dates
    return time
}
export function getDiffDay(date_1, date_2) {
    // 计算两个日期之间的差值
    let totalDays,diffDate
    let myDate_1 = date_1.getTime()
    let myDate_2 = date_2.getTime()
    // 将两个日期都转换为毫秒格式，然后做差
    diffDate = Math.abs(myDate_1 - myDate_2) // 取相差毫秒数的绝对值

    totalDays = Math.floor(diffDate / (1000 * 3600 * 24)) // 向下取整
    // console.log(totalDays)

    return totalDays    // 相差的天数
}
